<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_scbg_ok_t {
        background-color: #254060;
        height: 444px;
        color: white;
        overflow: auto;
    }

    .pa_scbg_ok {
        margin-top: 20px;
        height: 40px;
        line-height: 40px;
        width: 70%;
        margin-left: 20%;
        text-align: center;
    }

    .pa_scbg_ok_but {
        height: 150px;
        line-height: 150px;
        margin-top: 45px;
        width: 150px;
        font-size: 30px;
        color: white;
        margin-left: 20px;
        text-align: center;
    }

    .pa_scbg_ok input {
        height: 40px;
        min-height: 40px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>合格品报工</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12 pa_scbg_ok_t">
                <div class="aui-flex-col">
                    <div class="aui-flex-item-9">
                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    <span>工&nbsp&nbsp&nbsp&nbsp单&nbsp&nbsp&nbsp号：</span>
                                    <span id="workOrderCode"></span>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    <span>物&nbsp&nbsp料&nbsp编&nbsp码：</span>
                                    <span id="mrlCode"></span>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    <span>物&nbsp&nbsp料&nbsp名&nbsp称：</span>
                                    <span id="mrlName"></span>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    <span>可报工数量：</span>
                                    <span id="overageQty"></span>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    <span>批&nbsp&nbsp&nbsp&nbsp&nbsp次&nbsp&nbsp&nbsp&nbsp号：</span>
                                    <span id="lotCode"></span>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    容&nbsp&nbsp器&nbsp条&nbsp码：</div>
                                <div class="aui-list-item-input"
                                    style="background-color: white;float: left;width: 300px;">
                                    <input type="text" id="containerTm" class="aui-input" onclick="getIdSelector();" />
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_scbg_ok">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                    合&nbsp&nbsp格&nbsp数&nbsp量：</div>
                                <div class="aui-list-item-input"
                                    style="background-color: white;float: left;width: 300px;">
                                    <input type="number" id="qty" class="aui-input" onclick="getIdSelector();" />
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="aui-flex-item-3">
                        <div class="aui-flex-col">
                            <div class="pa_scbg_ok_but" style="background-color: #4B7902;" onclick="save()">
                                提交
                            </div>
                            <div class="pa_scbg_ok_but" style="background-color: #D9001B;" onclick="cancle()">
                                关闭
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    //光标所在id
    var idSelector = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        doSearch()

        api.setFocus({
            inputId: 'containerTm',
            focus: true
        })
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询工单信息
    function doSearch() {
        var workOrderCode = api.pageParam.workOrderCode;
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyWorkOrder";
        var data = {
            values: {
                workOrderCode: workOrderCode,
                proddate: api.pageParam.proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCenterName: api.pageParam.workCenterName,
                shiftCode: api.pageParam.shiftCode,
                state: "开工",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {

                    var list = eval(myobj.list);
                    if (list != null && list.length > 0) {
                        document.getElementById("workOrderCode").innerHTML = list[0].workOrderCode;
                        document.getElementById("mrlCode").innerHTML = list[0].mrlCode;
                        document.getElementById("mrlName").innerHTML = list[0].mrlName;
                        document.getElementById("lotCode").innerHTML = list[0].lotCode;
                        document.getElementById("overageQty").innerHTML = list[0].planQty - list[0].completeQty;
                    } else {
                        document.getElementById("workOrderCode").innerHTML = '';
                        document.getElementById("mrlCode").innerHTML = '';
                        document.getElementById("mrlName").innerHTML = '';
                        document.getElementById("lotCode").innerHTML = '';
                        document.getElementById("overageQty").innerHTML = '';
                        api.toast({
                            msg: "工单【" + workOrderCode + "】信息不存在！",
                            duration: 3000
                        });
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //保存
    function save() {
        var workOrderCode = document.getElementById("workOrderCode").innerHTML;
        var overageQty = parseInt(document.getElementById("overageQty").innerHTML);
        var containerTm = $("#containerTm").val();
        var qty = $("#qty").val();

        //工单号非空校验
        if (workOrderCode == null || workOrderCode == "" || workOrderCode == undefined) {
            api.toast({
                msg: '工单号不能为空！',
                duration: 3000
            });
            return;
        }

        //容器条码非空校验
        if (containerTm == null || containerTm == "" || containerTm == undefined) {
            api.toast({
                msg: '请扫描/录入容器条码！',
                duration: 3000
            });
            return;
        }

        //合格数量非空校验
        if (qty == null || qty == "" || qty == undefined) {
            api.toast({
                msg: '请录入合格数量！',
                duration: 3000
            });
            return;
        }

        //合格数量为正整数
        if (!new RegExp("^[0-9]*[1-9][0-9]*$").test(qty)) {
            api.toast({
                msg: '合格数量为正整数！',
                duration: 3000
            });
            return;
        }

        //合格数量不能大于报工剩余数
        if (parseInt(qty) > overageQty) {
            api.toast({
                msg: '合格数量不能大于可报工数量！',
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyReportSave";
        var data = {
            values: {
                workOrderCode: workOrderCode,
                workCellCode: api.pageParam.workCellCode,
                containerTm: containerTm,
                qty: qty,
                type: "0", //0合格 1不合格  
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    $("#containerTm").val("");
                    $("#qty").val("");
                    doSearch();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    $("#containerTm").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            console.log(tm);
            if (tm != null && tm != "" && tm != undefined) {
                $("#containerTm").blur();
                api.setFocus({
                    inputId: 'qty',
                    focus: true
                })
            }
        }
    });

    //取消按钮
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'productionAssemblyScbg',
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>